package cn.mumzone.pos.ui.adapter.inventory;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;

import cn.mumzone.pos.ui.widgets.tablayout.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import cn.mumzone.pos.ui.widgets.tablayout.buildins.commonnavigator.abs.IPagerIndicator;
import cn.mumzone.pos.ui.widgets.tablayout.buildins.commonnavigator.abs.IPagerTitleView;
import cn.mumzone.pos.ui.widgets.tablayout.buildins.commonnavigator.indicators.LinePagerIndicator;
import cn.mumzone.pos.ui.widgets.tablayout.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
import cn.mumzone.pos.ui.widgets.tablayout.buildins.commonnavigator.titles.SimplePagerTitleView;

/**
 * Created By Dlx
 * on 2019/9/26
 */
public class ADA_InventoryNavigation extends CommonNavigatorAdapter {

    private String[] titles;
    private OnTitleViewClickListener listener;

    public ADA_InventoryNavigation(String[] titles) {
        this.titles = titles;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public IPagerTitleView getTitleView(Context context, final int index) {
        SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
        simplePagerTitleView.setNormalColor(Color.GRAY);
        simplePagerTitleView.setSelectedColor(Color.BLACK);
        simplePagerTitleView.setText(titles[index]);
        simplePagerTitleView.setTextSize(getSpValue(18, context));
        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.onTitleClick(index);
                Log.e("ADAL", "onClick: " + index);
            }
        });
        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
        linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
        linePagerIndicator.setColors(Color.BLACK);
        return linePagerIndicator;
    }

    public void setListener(OnTitleViewClickListener listener) {
        this.listener = listener;
    }

    private float getSpValue(int spValue, Context context) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, context.getResources().getDisplayMetrics());
    }

    public interface OnTitleViewClickListener {
        void onTitleClick(int position);
    }
}
